﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class Files
    {
        public static int insert(FilesEntity files)
        {
            return Convert.ToInt32(DbHelper.ExecuteScalar("p_Files_insert",
              files.ImgName,
              files.SystemName,
              files.IsIndex,
              files.ProductId,
              files.FileCode
               ));
        }

        public static void delete(int filesId)
        {
            DbHelper.ExecuteNonQuery("p_Files_delete",
                filesId);
        }

        public static void update(FilesEntity files)
        {
            DbHelper.ExecuteNonQuery("p_Files_update",
              files.FilesId,
              files.ProductId,
              files.IsIndex
               );
        }

        public static FilesEntity getById(int filesId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_Files_getById", filesId);
            FilesEntity files = new FilesEntity();
            if (dr != null)
            {
                files.FilesId = filesId;
                files.ImgName = dr["imgName"].ToString();
                files.SystemName = dr["systemName"].ToString();
                files.CreateDt = Convert.ToDateTime(dr["createDt"]);
                files.IsIndex = Convert.ToBoolean(dr["isIndex"]);
                files.ProductId = Convert.ToInt32(dr["productId"]);
                files.FileCode = dr["fileCode"].ToString();
            }
            return files;
        }

        
        public static DataTable getListByProduct(int productId)
        {
            return DbHelper.ExecuteDataTable("p_Files_getListByProduct",
                productId);
        }
    }
}
